# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libyaml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.7
pkgrel=1
pkgdesc="YAML 1.1 library (mingw-w64)"
arch=('any')
url="http://yaml.org"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/yaml/libyaml/archive/${pkgver}.tar.gz
        "0001-Proper-mingw-YAML_DECLARE-definition.patch"
        "0002-libyaml-no-undefined.patch")
sha256sums=('e1884d0fa1eec8cf869ac6bebbf25391e81956aa2970267f974a9fa5e0b968e2'
            'b3c137a1d44432edc35e571b479a0f3f0315f664c994ea147f9c4a7167a9857c'
            '6e26d8ac24052239a1bc2db7e8d9cc28ece490a09c36479ca0209ee890ce387d')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-Proper-mingw-YAML_DECLARE-definition.patch"
  patch -Np1 -i "${srcdir}/0002-libyaml-no-undefined.patch"

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
